package org.jeecg.flowable.mapper.definition;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.jeecg.flowable.entity.definition.BpmTaskAssignRule;
import org.springframework.lang.Nullable;

import java.util.List;

@Mapper
public interface BpmTaskAssignRuleMapper extends BaseMapper<BpmTaskAssignRule> {

    default List<BpmTaskAssignRule> selectListByProcessDefinitionId(String processDefinitionId,
                                                                      @Nullable String taskDefinitionKey) {

        QueryWrapper<BpmTaskAssignRule> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("process_definition_id", processDefinitionId);
        if (taskDefinitionKey != null) {
            queryWrapper.eq("task_definition_key", taskDefinitionKey);
        }

        return selectList(queryWrapper);
    }

    default List<BpmTaskAssignRule> selectListByModelId(String modelId) {
        return selectList(new QueryWrapper<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .eq("process_definition_id", BpmTaskAssignRule.PROCESS_DEFINITION_ID_NULL));
    }

    default BpmTaskAssignRule selectListByModelIdAndTaskDefinitionKey(String modelId,
                                                                        String taskDefinitionKey) {
        return selectOne(new QueryWrapper<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .eq("process_definition_id", BpmTaskAssignRule.PROCESS_DEFINITION_ID_NULL)
                .eq("task_definition_key", taskDefinitionKey));
    }



}
